// The conversation object



function Conversation(ouruser, otheruser, win)
{
	this.ouruser = ouruser;
	this.otheruser = otheruser;
	this.messages = Array();
	this.win = win;

	function newmessage(user, msg, timestamp)
	{
		var username = user;
		if (usernames && usernames[user])
			username = usernames[user];

		this.messages.push({u : username, m : msg, t : timestamp});
	}

	function mymessage(msg, timestamp)
	{
		this.messages.push({u : this.ouruser, m: msg, t : timestamp});
	}

	function render()
	{
		var buf = '';
		for (i = 0; i < this.messages.length; i++)
		{
			buf += this.formatmsg(this.messages[i]["u"], this.messages[i]["m"], this.messages[i]["t"]);
		}
		return buf;
	}

	function fixscroll()
	{
		var convarea = document.getElementById(this.win + '_conv');
		var top = convarea.scrollHeight - convarea.clientHeight;
		if (top > 0) convarea.scrollTop = top;
	}

	function formatmsg(user, msg, t)
	{
		var d = new Date(t*1000);
		var h = d.getHours();
		var m = d.getMinutes();
		var s = d.getSeconds();

		if (h < 10)
			h = '0' + h;
		if (m < 10)
			m = '0' + m;
		if (s < 10)
			s = '0' + s;

		return "<div style=\"padding:2px 0 0 2px; font-size: 11px; border-bottom:1px dashed;\"><strong>(" + h + ":" + m + ":" + s + ") " + user + ":</strong> <br />" + smilify(msg,cp_basepath + '/jwc/') + "</div>";
	}
	this.newmessage = newmessage;
	this.mymessage = mymessage;
	this.render = render;
	this.formatmsg = formatmsg;
	this.fixscroll = fixscroll;
}


